package com.kk.xhr.model.dao;

import static com.kk.xhr.model.dao.SignDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.kk.xhr.model.entity.Sign;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface SignMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    BasicColumn[] selectList = BasicColumn.columnList(id, userId, begin, end, duration, lack, beginStatus, endStatus, signDate, status, created, updated);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<Sign> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("SignResult")
    Optional<Sign> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="SignResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="begin", property="begin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end", property="end", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="duration", property="duration", jdbcType=JdbcType.REAL),
        @Result(column="lack", property="lack", jdbcType=JdbcType.INTEGER),
        @Result(column="begin_status", property="beginStatus", jdbcType=JdbcType.TINYINT),
        @Result(column="end_status", property="endStatus", jdbcType=JdbcType.TINYINT),
        @Result(column="sign_date", property="signDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="created", property="created", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updated", property="updated", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Sign> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, sign, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, sign, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int insert(Sign record) {
        return MyBatis3Utils.insert(this::insert, record, sign, c ->
            c.map(userId).toProperty("userId")
            .map(begin).toProperty("begin")
            .map(end).toProperty("end")
            .map(duration).toProperty("duration")
            .map(lack).toProperty("lack")
            .map(beginStatus).toProperty("beginStatus")
            .map(endStatus).toProperty("endStatus")
            .map(signDate).toProperty("signDate")
            .map(status).toProperty("status")
            .map(created).toProperty("created")
            .map(updated).toProperty("updated")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int insertSelective(Sign record) {
        return MyBatis3Utils.insert(this::insert, record, sign, c ->
            c.map(userId).toPropertyWhenPresent("userId", record::getUserId)
            .map(begin).toPropertyWhenPresent("begin", record::getBegin)
            .map(end).toPropertyWhenPresent("end", record::getEnd)
            .map(duration).toPropertyWhenPresent("duration", record::getDuration)
            .map(lack).toPropertyWhenPresent("lack", record::getLack)
            .map(beginStatus).toPropertyWhenPresent("beginStatus", record::getBeginStatus)
            .map(endStatus).toPropertyWhenPresent("endStatus", record::getEndStatus)
            .map(signDate).toPropertyWhenPresent("signDate", record::getSignDate)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(created).toPropertyWhenPresent("created", record::getCreated)
            .map(updated).toPropertyWhenPresent("updated", record::getUpdated)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default Optional<Sign> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, sign, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default List<Sign> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, sign, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default List<Sign> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, sign, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default Optional<Sign> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, sign, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    static UpdateDSL<UpdateModel> updateAllColumns(Sign record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(userId).equalTo(record::getUserId)
                .set(begin).equalTo(record::getBegin)
                .set(end).equalTo(record::getEnd)
                .set(duration).equalTo(record::getDuration)
                .set(lack).equalTo(record::getLack)
                .set(beginStatus).equalTo(record::getBeginStatus)
                .set(endStatus).equalTo(record::getEndStatus)
                .set(signDate).equalTo(record::getSignDate)
                .set(status).equalTo(record::getStatus)
                .set(created).equalTo(record::getCreated)
                .set(updated).equalTo(record::getUpdated);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Sign record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(userId).equalToWhenPresent(record::getUserId)
                .set(begin).equalToWhenPresent(record::getBegin)
                .set(end).equalToWhenPresent(record::getEnd)
                .set(duration).equalToWhenPresent(record::getDuration)
                .set(lack).equalToWhenPresent(record::getLack)
                .set(beginStatus).equalToWhenPresent(record::getBeginStatus)
                .set(endStatus).equalToWhenPresent(record::getEndStatus)
                .set(signDate).equalToWhenPresent(record::getSignDate)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(created).equalToWhenPresent(record::getCreated)
                .set(updated).equalToWhenPresent(record::getUpdated);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int updateByPrimaryKey(Sign record) {
        return update(c ->
            c.set(userId).equalTo(record::getUserId)
            .set(begin).equalTo(record::getBegin)
            .set(end).equalTo(record::getEnd)
            .set(duration).equalTo(record::getDuration)
            .set(lack).equalTo(record::getLack)
            .set(beginStatus).equalTo(record::getBeginStatus)
            .set(endStatus).equalTo(record::getEndStatus)
            .set(signDate).equalTo(record::getSignDate)
            .set(status).equalTo(record::getStatus)
            .set(created).equalTo(record::getCreated)
            .set(updated).equalTo(record::getUpdated)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: sign")
    default int updateByPrimaryKeySelective(Sign record) {
        return update(c ->
            c.set(userId).equalToWhenPresent(record::getUserId)
            .set(begin).equalToWhenPresent(record::getBegin)
            .set(end).equalToWhenPresent(record::getEnd)
            .set(duration).equalToWhenPresent(record::getDuration)
            .set(lack).equalToWhenPresent(record::getLack)
            .set(beginStatus).equalToWhenPresent(record::getBeginStatus)
            .set(endStatus).equalToWhenPresent(record::getEndStatus)
            .set(signDate).equalToWhenPresent(record::getSignDate)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(created).equalToWhenPresent(record::getCreated)
            .set(updated).equalToWhenPresent(record::getUpdated)
            .where(id, isEqualTo(record::getId))
        );
    }
}